<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/14
 * Time: 16:10
 */
trait util_person
{

    public static $util_admin_person_instance = null;

    //easy get admin person
    public static function util_admin_person()
    {
        if (empty(self::$util_admin_person_instance)) {
            $array = Yii::app()->params;
            $adminName = MsggGlobalConfig::getGloabalConfigValue(
                MsggGlobalConfig::CONFIG_ADMIN_NAME,
                isset($array[MsggGlobalConfig::CONFIG_ADMIN_NAME]) ? $array[MsggGlobalConfig::CONFIG_ADMIN_NAME] : '');
            self::$util_admin_person_instance = AlarmPerson::model()->findByAttributes(['name' => $adminName]);
        }
        return self::$util_admin_person_instance;

    }

    public static function util_admin_mail()
    {
        $admin = self::util_admin_person();
        if (!empty($admin)) {
            return $admin->mail;
        }
        return empty(Yii::app()->params['admin_email']) ? null : Yii::app()->params['admin_email'];
    }


}